/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86156
 * Date: 2023-04-04
 * Time: 18:55
 */

import java.util.Random;
import java.util.Scanner;


// 算术运算符 + - * / %

public class ArithmeticOperator {
    // 键盘录入一个三位数,分别打印其个位,十位,百位
    public static void main1(String[] args) {
        // 键盘录入
        System.out.println("请输入你要拆分的数字");
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();

        System.out.println(input % 10);
        System.out.println(input / 10 % 10);
        System.out.println(input / 100 % 10);
    }

    // 隐式转换和强制转换
    public static void main(String[] args) {
        // 隐式转换的两种规则
        // 取值范围小的和取值范围大德进行运算时,小的会先提升为大的,再进行运算
        // byte short char先转换为int在运算
        // 取值范围 byte<short<int<long<float<double

        // 强制转换
    }
}



// 分支循环 switch 新特性
class Test{
    public static void main(String[] args) {
        int values=0;
        switch(values){
            case 1->{
                System.out.println("一");
            }
            case 2->{
                System.out.println("二");
            }
            default ->{
                System.out.println("没有这种选项");
            }
        }
    }
}


// 回文数
class Test2{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要判断的数字");
        int input = 122;
        int tmp=input;
        int sum=0;

        while(tmp!=0){
            int ret=tmp%10;
            tmp/=10;

            sum=sum*10+ret;
        }

        System.out.println(sum);
        System.out.println(input);

        System.out.println(sum == input);
    }
}


// 生成随机数
class Test3{
    public static void main(String[] args) {
       // 创建对象
        Random random = new Random(100);

        // 生成随机数
        // 生成的随机数一定是从零开始的
        // 包头不包位,包左不包右

        int number=random.nextInt(100)+1; // 0~99

        System.out.println(number);
    }
}

// 数组遍历 要求便利的结果在一行上
class Test4{
    public static void main(String[] args) {
        int [] array={1,2,3,4,5};
        System.out.print("[");
        for (int i = 0; i < array.length; i++) {
            if(i==array.length-1) {
                System.out.print(array[i]);
                break;
            }
            System.out.print(array[i] + ",");
        }
        System.out.println("]");
    }
}

// 把一个数组的元素从from到to的元素赋值到一个新的数组,并打印该数组
class Teat5{
    public static void main(String[] args) {
        int [] arr={1,2,3,4,5,6,7,8,9,10};
        int array[] = copyOfRange(arr,3,7);

        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

    public static int[] copyOfRange(int [] arr,int from ,int to){
        int len=to-from;
        int [] array=new int[len+1];
        for (int i = from,j=0; i <=to; i++,j++) {
            array[j]=arr[i];
        }
        return array;
    }
}

// 随机验证码 前四位是字母,后一位是数字
class Test6{
    public static void main(String[] args) {
        char[] ch= new char[52];
        // 添加字母
        for (int i = 0; i < ch.length; i++) {
            // 添加小写字母
            if(i<=25){
                ch[i]=(char)(97+i);
            }
            else{
                // 添加大写字母
                ch[i] = (char)(65+i-26);
            }
        }

        // 随机生成
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int j = r.nextInt(52);
            System.out.print(ch[j]);
            if(i==3){
                System.out.print(r.nextInt(10));
            }
        }
    }
}


// 双色球彩票系统
class Test7{
    public static void main(String[] args) {
        // 1.生成中奖号码
        int [] arr = createNumber();
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

        System.out.println();
        // 2.用户购买号码
        int [] userInputArr = inputNumber();

        // 3.判断中奖
        // 红球,篮球分开判断
        int redCount=0;
        int blueCount=0;

        // 判断红球
        for (int i = 0; i < userInputArr.length-1; i++) {
            int number = userInputArr[i];

            for (int j = 0; j < arr.length-1; j++) {
                if(number == arr[i]){
                    redCount++;
                    break;
                }
            }
        }
        // 判断篮球
        if(arr[arr.length-1] == userInputArr[userInputArr.length-1]){
            blueCount++;
        }
        System.out.println(redCount);
        System.out.println(blueCount);

        if((redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount ==1)){
            System.out.println("您中了五元!");
        } else if ((redCount == 3 && blueCount == 1) || (redCount == 2 && blueCount ==1)) {
            System.out.println("您中了十元!");
        } else if ((redCount == 4 && blueCount == 1) || (redCount == 4 && blueCount == 0)) {
            System.out.println("您中了200");
        } else if ((redCount == 5 && blueCount == 1) || (redCount == 5 && blueCount == 0)) {
            System.out.println("您中了2000");
        } else if ((redCount == 6 && blueCount == 0)) {
            System.out.println("您中了500万");
        } else if ((redCount == 6 && blueCount == 1)) {
            System.out.println("您中了一千万");
        }
    }

    public static int[] inputNumber(){
        int [] array=new int[7];
        Scanner sc = new Scanner(System.in);
        int index = 0;
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第"+(i+1)+"个号码");
            int inputNumber = sc.nextInt();
            boolean flag = contains(array,inputNumber);
            if(!flag){
                if(inputNumber>0 && inputNumber <= 33){
                    array[i] = inputNumber;
                    i++;
                    index++;
                }else{
                    System.out.println("输入所值超出限制,请重新输入");
                }
            }else{
                System.out.println("输入数字重复,请重新输入");
            }
        }

        while(true) {
            System.out.println("请输入第" + (index + 1) + "个号码");
            int inputNumber = sc.nextInt();
            if (inputNumber > 0 && inputNumber <= 16) {
                array[index] = inputNumber;
                break;
            } else {
                System.out.println("输入所值超出限制,请重新输入");
            }
        }
        return array;
    }




    public static int[] createNumber(){
        // 创建数组用于添加中奖号码
        // 六个红球,一个篮球
        // 要求红球不能重复,篮球可以和红球相等
        int [] arr = new int[7];
        Random random = new Random();
        int index=0;
        // 生成红球号码
        for (int i = 0; i < 6; ) {
            int redNumber = random.nextInt(33)+1;
            boolean flag = contains(arr,redNumber);
            if(!flag){
                arr[i] = redNumber;
                i++;
                index++;
            }
        }
        // 生成篮球号码
        int blueNumber = random.nextInt(16)+1;
        arr[index] = blueNumber;

        return arr;
    }

   public static boolean contains(int [] arr,int number){
       for (int i = 0; i < arr.length; i++) {
           if(arr[i] == number){
               return true;
           }
       }
       return false;
   }
}


